package com.sc.controller.rui;

import com.sc.domain.Person;
import com.sc.dto.CheckDto;
import com.sc.dto.PersonDto;
import com.sc.result.Result;
import com.sc.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author: Rui
 * @Date: 2024/11/28 20:57
 */
@CrossOrigin
@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private PersonService personService;

//    删除住户
    @DeleteMapping("delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        return Result.success("删除成功",personService.deleteById(id));
    }

//    添加住户
    @PostMapping("add")
    public Result add(@RequestBody Person person) {
        return Result.success("添加成功",personService.add(person));

    }

//    修改时候住户信息的回显
    @GetMapping("selectById")
    public Result selectById(Integer id) {
        return Result.success("查询成功",personService.selectById(id));
    }

//    修改住户
    @PutMapping("update")
    public Result update(@RequestBody Person person) {
        return Result.success("修改成功",personService.update(person));
    }

//    显示住户列表（包含了分页查询，模糊查询，左侧导航栏查询）
    @PostMapping("list")
    public Result list(@RequestBody PersonDto personDto) {
        return Result.success("查询成功",personService.list(personDto));
    }

//    显示住户详细信息
    @GetMapping("detailById")
    public Result detail(Integer id) {
        return Result.success("查询成功",personService.selectDetailById(id));
    }

    @GetMapping("detailByName")
    public Result detailByName(@RequestParam String name) {
        Map<String, Object> result = personService.selectDetailByName(name);
        return Result.success("查询成功", result);
    }

//    详情界面是否通过审核
    @PutMapping("check")
    public Result check(@RequestBody CheckDto checkdto) {
        return Result.success("审核成功",personService.updateCheck(checkdto));
    }

//    根据数组id删除多个住户
    @DeleteMapping("deleteByIds")
    public Result deleteByIds(@RequestBody List<Integer> ids) {
        return Result.success("删除成功",personService.deleteByIds(ids));
    }
}
